package com.personal.delete;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;


/**
 * 
 * @author Liang Wenjun
 * @Date 2017-05-08 12:05:05
 *
 */
public class AutoFlushToken extends DeleteDao{
	
	public static void main(String[] args) {
		int num = 0;
		Properties prop = readPropertiesFile();
		String exceptionMsg =prop.getProperty("exceptionMsg");
			if(args.length != 1 ){
				System.out.println(exceptionMsg);
				return;
			}else{
				try{
					 num = Integer.parseInt(args[0]);
				}catch (Exception e) {
					System.out.println(exceptionMsg);
					return;
				}
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					System.out.println("*************************************************");
					System.out.println("currentTime:"+ sdf.format(new Date()));
					System.out.println("DB connection info :" + prop.getProperty("DB_URL"));
					System.out.println("DB username:"+ prop.getProperty("USER_NAME"));
					System.out.println("delete token begin!");
					inputDayNum(num);
					System.out.println("delete token complete!");
					System.out.println("*************************************************");
					return;
				}
	}
	
	public static void inputDayNum(int input){
		int count = 0;
		AutoFlushToken aft = new AutoFlushToken();
		count = aft.delete(input,0);
		System.out.println("table:cas_service_ticket "+count+" rows is deleted");
		count = aft.delete(input,1);
		System.out.println("table:cas_ticket_granting_ticket "+count+" rows is deleted");
		count = aft.delete(input,2);
		System.out.println("table:ws_log "+count+" rows is deleted");
	}
}
